<?php


namespace Xiaoguai\DesignPattern\DP023;


use Xiaoguai\DesignPattern\DP023\Expression\AndExpression;
use Xiaoguai\DesignPattern\DP023\Expression\TerminalExpression;

class Context
{
    protected $cities = ["韶关", "广州"];

    protected $persons = ["老人", "妇女", "儿童"];

    protected $cityPersonExpression;

    /**
     * 构建And表达式
     * Context constructor.
     */
    public function __construct()
    {
        $cityExpression = new TerminalExpression($this->cities);
        $personExpression = new TerminalExpression($this->persons);

        $this->cityPersonExpression = new AndExpression($cityExpression, $personExpression);
    }

    /**
     * 对表达式传参计算
     * @param string $info
     * @return bool
     */
    public function freeRide(string $info): bool
    {
        return $this->cityPersonExpression->interpret($info);
    }
}